package com.zhuhjay.config;

import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

/**
 * @author ZhuHJay
 * @date 2023/4/25 22:51
 */
@Configuration
public class CaffeineCacheConfig {

    /** 登录用户缓存配置 */
    @Bean
    public Cache<String, Object> loginUserCache() {
        return Caffeine.newBuilder()
                .expireAfterWrite(30 * 60, TimeUnit.SECONDS)
                .maximumSize(100)
                .build();
    }

    /** 验证码缓存配置 */
    @Bean
    public Cache<String, String> codeCache() {
        return Caffeine.newBuilder()
                .expireAfterWrite(5 * 60, TimeUnit.SECONDS)
                .maximumSize(100)
                .build();
    }

}
